<template>
  <van-tabbar
    v-model="select"
    active-color="#f00"
    inactive-color="#000"
    @change="changeTabbar"
  >
    <van-tabbar-item icon-prefix="iconfont" icon="shouye">首页</van-tabbar-item>
    <van-tabbar-item icon-prefix="iconfont" icon="shouye1"
      >分类</van-tabbar-item
    >
    <van-tabbar-item v-if="$store.getters.getBadgeCount > 0" icon-prefix="iconfont" icon="fenlei01" :badge="$store.getters.getBadgeCount"
      >购物车</van-tabbar-item
    >
     <van-tabbar-item v-else icon-prefix="iconfont" icon="fenlei01"
      >购物车</van-tabbar-item
    >
    <van-tabbar-item icon-prefix="iconfont" icon="gerenzhongxin"
      >我的</van-tabbar-item
    >
  </van-tabbar>
</template>

<script>
export default {
  props: {
    active: {
      type: Number,
      default: 0
    },
  },
  data() {
    return {
      select: 0,
    }
  },
  created() {
    this.select = this.active
  },
  methods: {
    changeTabbar(index) {
      // console.log('index:', index);
      if (index === 0) {
        this.$router.push("/").catch(() => {});
      } else if (index === 1) {
        this.$router.push("/category").catch(() => {});
      } else if (index === 2) {
        this.$router.push("/shopcar").catch(() => {});
      } else if (index === 3) {
        this.$router.push("/me").catch(() => {});
      }
    },
  },
};
</script>

<style lang="scss" scoped>
</style>